<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="email=no">
<title>订单详情</title>
<link href="css/iconfont.css" rel="stylesheet" type="text/css" />
<link href="css/basestyle.css" rel="stylesheet" type="text/css" />
<link href="css/common.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="../css/order.css" rel="stylesheet" type="text/css" />

</head>

<body style="background:#fff">
<div class="wx-container">
	<a href="#" >
			 <img style="height: 3rem; width: 3rem;margin: 20rem 45%;" src="../images/loading.gif" alt="加载中" ppsrc="img/0da8eb94-0159-4700-a6a5-bc007da5a853.jpg">
	   </a>
	
</div>
<div class="ft-blank"></div>
<div class="footer-btn">
	<a href="#" >
			 <img style="height: 2rem; width: 2rem;margin: 1rem 46%;" src="../images/loading.gif" alt="加载中" ppsrc="img/0da8eb94-0159-4700-a6a5-bc007da5a853.jpg">
	  </a>
</div>
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<!-- cookie操作js -->
<script charset="utf-8" src="../js/global.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/StringBuilder.js"></script>
<script type="text/javascript" src="../js/templeteHtml.js"></script>
<script type="text/javascript" src="../js/wxLoginInfo.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript">
$(function(){
	
	loginInfo(function(userInfo){
	$.post("../xxorder/getOrderDetatil",{memberId:userInfo.id,sn:parseURL(window.location.search).sn},function(ret){
			if(ret&&ret.code==200){
				var datas=ret.data;
				console.log(datas.order_status);
				var html="";
				if(datas.order_status<0){//订单关闭
					html=String.formatmodel(templete.getOrderDetailClose(),datas);
				}
				if(datas.order_status==0){
					html=String.formatmodel(templete.getOrderDetailLead(),datas);
				}
				if(datas.order_status==1){
					html=String.formatmodel(templete.getOrderDetailLeading(),datas);
				}
				if(datas.order_status==2){
					html=String.formatmodel(templete.getOrderDetailSuccess(),datas);
				}
				if(datas.order_status==3){
					html=String.formatmodel(templete.getOrderDetailSuccess(),datas);
				}
				html+=String.formatmodel(templete.getOrderDetailAddr(),datas);
				var xxOrderItems=datas.xxOrderItems;
				for(var i in xxOrderItems){
					if(xxOrderItems[i].thumbnail.indexOf(",")>0){
						xxOrderItems[i].thumbnail=(xxOrderItems[i].thumbnail.split(",")[0]);
					}
					html+=String.formatmodel(templete.getOrderDetailProduct(),xxOrderItems[i]);
				}
				datas.total=datas.xxPayment.amount;
				html+=String.formatmodel(templete.getOrderDetailCateMy(),datas);
				html+=String.formatmodel(templete.getOrderDetailMemo(),datas);
				html+=String.formatmodel(templete.getOrderDetailEnd(),{expire:datas.expire,create_date:datas.create_date,orderSn:datas.sn,xxPaySn:datas.xxPayment.sn});
				$(".wx-container").html(html);
				if(datas.order_status<0){//订单关闭
					
				}
				if(datas.order_status==0){
					$(".footer-btn").html(String.formatmodel(templete.getOrderDetailPay(),{totalMoney:datas.xxPayment.amount*1+datas.freight*1,payMentId:datas.xxPayment.id,xxPaySn:datas.xxPayment.sn}));
				}
				if(datas.order_status==1){
					$(".footer-btn").html(String.formatmodel(templete.getOrderDetailConfirmOrder(),{totalMoney:datas.xxPayment.amount*1+datas.freight*1,payMentId:datas.xxPayment.id}));
				}
				if(datas.order_status==2){
					$(".footer-btn").html(String.formatmodel(templete.getOrderDetailPingjiaOrder(),{totalMoney:datas.xxPayment.amount*1+datas.freight*1,payMentId:datas.xxPayment.id}));
				}
				if(datas.order_status==3){
					$(".footer-btn").html(String.formatmodel(templete.getOrderDetailSuccessOrder(),{totalMoney:datas.xxPayment.amount*1+datas.freight*1,payMentId:datas.xxPayment.id}));
				}
			}
		},'json')
	})
})	
//调用微信支付
function payMoney(paymentSn){
	//暂时就直接更新订单状态
	var code=parseURL(window.location.search).code;
	var payOpenid=jQuery.getCookie("payOpenid");
	if(payOpenid==undefined||payOpenid==""||payOpenid==null){
		$.get("../home/getAppidByCode",{code:code},function(res){
			if(res&&res.code==200){
				payOpenid=res.data.openid;
				jQuery.setCookie("payOpenid",payOpenid,null);//便于用户取消支付之后在次点击支付
				pay(paymentSn,payOpenid);
			}
		},'json');
	}else{
		pay(paymentSn,payOpenid);
	}
}
//支付订单的sn单号 付款微信号与收款公众号的唯一标识openid
function pay(paymentSn,payOpenid){
	$.post("../xxorder/payOrder",{paymentSn:paymentSn,payOpenid:payOpenid},function(ret){
		if(ret&& ret.code==200&&ret.data){
			var datas=ret.data;
			console.log(datas);
			var pak = datas.package ;
			console.log(pak);
			   WeixinJSBridge.invoke('getBrandWCPayRequest', {
				           "appId":datas.appId,     //公众号名称，由商户传入     
				           "timeStamp":datas.timeStamp,         //时间戳，自1970年以来的秒数     
				           "nonceStr":datas.nonceStr, //随机串     
				           "package":pak,     
				           "signType":datas.signType,         //微信签名方式：     
				           "paySign":datas.sign //微信签名 
				       },
				       function(res){     
				    	   //alert(JSON.stringify(res));
				           if(res.err_msg == "get_brand_wcpay_request:ok" ) {
				        	   //alert(res.result_code);
				        	   location.replace(getRealPath()+"/my/paySuccess.html");
				        	  //location.href='./paySuccess.html' ;
					        }
				           //location.href='./paySuccess.html' ;    
					           // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。 
					   }
				   ); 
		}
	},'json');
}



</script>
</body>
</html>